/**
 * 
 */
package com.nwpusp.transmitter;


import java.io.Closeable;
import java.util.ArrayList;

import com.nwpusp.controller.actions.Action;
import com.nwpusp.model.session.ConnectionId;

/**
 * @author JustinCao
 *
 */
public abstract class Transmitter {
	private TransmitterListener listener = null;

	public Transmitter(TransmitterListener listener) {
		this.listener = listener;
	}
	
	public void notifyReceive(ConnectionId from, ArrayList<Action> al) {
		if(listener != null) {
			listener.OnReceive(this, from, al);
		}
	}
/*
 * // for client only
	public void notifyConnect(ConnectionId host, boolean success) {

		if(listener != null) {
			listener.OnConnect(this, host, success);
		}
	}
*/
	// for server only
	public boolean notifyAccept(ConnectionId client) {
		boolean isAccept = false;
		if(listener != null) {
			isAccept = listener.OnAccept(this, client);
		}
		return isAccept;
	}
	
	public void notifyEstablished(ConnectionId client, boolean success) {
		if(listener != null) {
			listener.OnEstablished(this, client, success);
		}
	}
	
	public void notifyDisconnect(ConnectionId cid) {
		if(listener != null) {
			listener.OnDisconnect(this, cid);
		}
	}
	
	public String notifyTellBroadCastString() {
		if(listener != null) {
			return listener.OnGetBroadcastName(this);
		}
		return "";
	}
	
	public abstract ConnectionId getLocalConnectionId();
	public abstract boolean  Listen(ConnectionId host); // cannot establish when returen false
	public abstract boolean Send(ConnectionId to, ArrayList<Action> al);
	public abstract boolean Connect(ConnectionId host);
	public abstract ArrayList<ConnectionId> dectectHosts();
	public abstract void shutDown();
}
